<div class="content-wrapper">
    <?php
    $form = $this->form;
    $form->prepare();

    ?>
    <?php echo $this->form()->openTag($form); ?>
    <section class="content-header">
        <?php echo $this->partial('layout/breadcrumb'); ?>

        <h1 class="pull-right" id="dbshop-menu-top">
            <a href="<?php echo $this->url('goods-common');?>" class="btn btn-default btn-sm"><i class="fa fa-arrow-left"></i> <?php echo $this->translate('返回通用内容列表'); ?></a>
            <button type="submit" class="btn btn-primary btn-sm"><i class="fa fa-check"></i> <?php echo $this->translate('保存通用内容'); ?></button>
            <?php echo $this->HelpUrl('goodsCommonAdd'); ?>
        </h1>
    </section>

    <section class="content">

        <div class="row">
            <div class="col-md-12">
                <div class="nav-tabs-custom">
                    <ul class="nav nav-tabs">
                        <li class="active"><a href="#tab_1" data-toggle="tab"><?php echo $this->translate('基本信息'); ?></a></li>
                        <li><a href="#tab_2" data-toggle="tab"><?php echo $this->translate('应用商品分类'); ?></a></li>
                    </ul>
                    <div class="tab-content">
                        <div class="tab-pane active" id="tab_1">
                            <div class="box-body">
                                <?php echo $this->formElementErrors($form->get('classId'), ['class'=>'error-message']); ?>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label"><?php echo $this->translate('内容简介'); ?><span class="must_add_value">*</span></label>
                                    <div class="col-sm-6">
                                        <?php echo $this->formElement($form->get('contentTitle')); ?>
                                        <?php echo $this->formElementErrors($form->get('contentTitle'), ['class'=>'error-message']); ?>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label"><?php echo $this->translate('排序'); ?><span class="must_add_value">*</span></label>
                                    <div class="col-sm-2">
                                        <?php echo $this->formElement($form->get('contentSort')); ?>
                                        <?php echo $this->formElementErrors($form->get('contentSort'), ['class'=>'error-message']); ?>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label"><?php echo $this->translate('状态'); ?></label>
                                    <div class="col-sm-4">
                                        <div class="checkbox">
                                            <label>
                                                <?php echo $this->formElement($form->get('contentState')); ?><?php echo $this->translate('启用'); ?>
                                                <?php echo $this->formElementErrors($form->get('contentState'), ['class'=>'error-message']); ?>
                                            </label>
                                        </div>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label"><?php echo $this->translate('通用内容'); ?></label>
                                    <div class="col-sm-10">
                                        <script id="contentBody" name="contentBody" type="text/plain"><?php echo isset($this->commonContent) ? $this->commonContent->getContentBody() : $form->get('contentBody')->getValue(); ?></script>
                                        <?php echo $this->formElementErrors($form->get('contentBody'), ['class'=>'error-message']); ?>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="tab-pane" id="tab_2">
                            <div class="box-body">
                                <p class="text-light-blue"><?php echo $this->translate('通用内容只应用于商品主分类'); ?></p>
                                <div class="box-body table-responsive no-padding">
                                    <table class="table table-hover">
                                        <thead>
                                        <tr><th><input type="checkbox" class="minimal select-all-class-checkbox"> <?php echo $this->translate('全选'); ?></th></tr>
                                        </thead>
                                        <tbody>
                                        <?php if($this->classList) foreach ($this->classList as $classValue) { ?>
                                            <tr>
                                                <td>
                                                    <label class="checkbox-inline col-sm-12">
                                                        <?php if($classValue->getClassTopId() > 0) echo str_repeat('&nbsp;', substr_count($classValue->getClassPath(), ',') * 3); ?>
                                                        <input onclick="selectClassId('<?php echo $classValue->getClassPath(); ?>', <?php echo $classValue->getClassId(); ?>);" name="classId[]" <?php if(isset($this->idArray) && !empty($this->idArray) && in_array($classValue->getClassId(), $this->idArray)) echo 'checked'; ?> id="classId<?php echo $classValue->getClassId(); ?>" value="<?php echo $classValue->getClassId(); ?>" type="checkbox" class="minimal">
                                                        <?php echo $this->escapeHtml($classValue->getClassName()); ?>
                                                    </label>
                                                </td>
                                            </tr>
                                        <?php } ?>
                                        </tbody>
                                    </table>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

            </div>
        </div>

    </section>
    <?php echo $this->form()->closeTag(); ?>

</div>
<?php echo $this->partial('common/editor', ['edit_array'=>['contentBody'], 'edit_config'=>["initialFrameHeight:450", 'serverUrl:"'.$this->url('editor', ['action'=> 'uEditorUpload', 'type' =>'goodsCommon']).'"']]); ?>
<script type="text/javascript">
    $(document).ready(function() {
        $("#<?php echo $form->getName(); ?>").validate({
            rules: {
                contentTitle: {
                    required: true
                },
                contentSort: {
                    required: true,
                    number: true,
                    min: 1
                }
            },
            messages: {
                contentTitle: {
                    required: "<?php echo $this->translate('内容简介不能为空!'); ?>"
                },
                contentSort: {
                    required: "<?php echo $this->translate('排序不能为空!'); ?>",
                    number: "<?php echo $this->translate('排序必须为数字!'); ?>",
                    min: "<?php echo $this->translate('排序最小为1!'); ?>"
                }
            }
        });

        $(".select-all-class-checkbox").click(function () {
            let checkState = this.checked;
            if(!checkState) {
                $("input[name='classId[]']").prop("checked", false);
                $(".select-all-class-checkbox").prop("checked", false);
            } else {
                $("input[name='classId[]']").prop("checked", true);
            }
        });
    });
</script>
